package mapelements.background;

import java.util.Vector;


/**rappresenta la classe usata per gestire e spedire i messaggi di tipo BackgroundEvent
 * 
 * @author koldar
 * @version 1.0
 */
public class BackgroundEventDispatcher extends Object implements Cloneable{
	
	private Vector<BackgroundListener> listeners;
	
	public BackgroundEventDispatcher(){
		super();
		this.listeners=new Vector<BackgroundListener>(0,1);
	}
	
	public void addBackgroundListener(BackgroundListener arg0){
		this.listeners.add(arg0);
	}
	
	public void removeBackgroundListener(BackgroundListener arg0){
		this.listeners.remove(arg0);
	}
	
	public void fireBackgroundEvent(BackgroundEvent arg0){
		for (BackgroundListener l:this.listeners){
			l.backgroundChanged(arg0);
		}
	}
	
	public void fireBackgroundEvent(Background source,int action){
		BackgroundEvent event=new BackgroundEvent(source,action);
		for (BackgroundListener l:this.listeners){
			l.backgroundChanged(event);
		}
	}
	
	/**crea una copia (senza tuttavia copiare i listener immagazzinati) di questa classe
	 * 
	 */
	public BackgroundEventDispatcher clone() throws CloneNotSupportedException{
		BackgroundEventDispatcher cloned=(BackgroundEventDispatcher) super.clone();
		cloned.listeners=new Vector<BackgroundListener>(0,1);
		return cloned;
	}

}
